package com.zhz.common.tool.mybatisplus.base.core.enums;

/**
 * 错误异常码
 * @author zhouhengzhe
 */
public enum ErrorCodeEnum  implements IEnum<Integer>, EnumValueResolver<ErrorCodeEnum, Integer> {
    PARAMETER_VALIDATION_FAILED(10000, "参数校验失败"),
    DB_OPERATION_EXCEPTION(10001, "数据库操作异常"),
    REQUEST_INTERFACE_TIMEOUT(10002, "接口请求超时"),
    REQUEST_INTERFACE_ERROR(10004, "接口请求异常"),
    REPEATED_REQUESTS(10003, "重复/频繁请求");

    private Integer code;
    private String desc;

    private ErrorCodeEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static String getDescByCode(Integer code) {
        String desc = "";
        ErrorCodeEnum[] var2 = values();
        int var3 = var2.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            ErrorCodeEnum codeEnum = var2[var4];
            if (codeEnum.getCode().equals(code)) {
                desc = codeEnum.getMessage();
                break;
            }
        }

        return desc;
    }

    public static ErrorCodeEnum getByCode(Integer code) {
        ErrorCodeEnum resultCodeEnum = null;
        ErrorCodeEnum[] var2 = values();
        int var3 = var2.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            ErrorCodeEnum codeEnum = var2[var4];
            if (codeEnum.getCode().equals(code)) {
                resultCodeEnum = codeEnum;
                break;
            }
        }

        return resultCodeEnum;
    }

    /**
     * 获取编码
     *
     * @return
     */
    @Override
    public Integer getCode() {
        return this.code;
    }

    /**
     * 获取描述
     *
     * @return
     */
    @Override
    public String getMessage() {
        return this.desc;
    }
}
